<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
	xmlns:ui="http://java.sun.com/jsf/facelets"
	xmlns:h="http://java.sun.com/jsf/html"
	xmlns:f="http://java.sun.com/jsf/core"
	xmlns:p="http://primefaces.org/ui">


<ui:composition template="/templates/templateAdmin.xhtml">
	<ui:define name="conteudo">
		<h:form id="listar">
			<p:dataTable value="#{mBDisciplina.listaDisc}" var="disciplina" emptyMessage="Nenhuma disciplina cadastrada" rows="10" paginator="true">
				<p:column headerText="Nome" filterBy="#{disciplina.nome}" filterMatchMode="contains">
					<p:commandLink value="#{disciplina.nome}" oncomplete="disciplinaDialog.show()" update="@form">
						<f:setPropertyActionListener target="#{mBDisciplina.disciplinaVisualizacao}" value="#{disciplina}"></f:setPropertyActionListener>
					</p:commandLink>
				</p:column>
				<p:column headerText="Sigla" filterBy="#{disciplina.sigla}" filterMatchMode="contains">
					<p:commandLink value="#{disciplina.sigla}" oncomplete="disciplinaDialog.show()" update="@form">
						<f:setPropertyActionListener target="#{mBDisciplina.disciplinaVisualizacao}" value="#{disciplina}"></f:setPropertyActionListener>
					</p:commandLink>
				</p:column>
				<p:column headerText="Ações">
					<p:commandButton value="Editar" action="#{mBDisciplina.irEditar}" ajax="false">
						<f:setPropertyActionListener target="#{mBDisciplina.disciplina}" value="#{disciplina}" />
					</p:commandButton>
					<p:commandButton value="Excluir" oncomplete="confirmation.show()">
						<f:setPropertyActionListener target="#{mBDisciplina.disciplina}" value="#{disciplina}" />
					</p:commandButton>
					
					<p:confirmDialog id="confirmDialog"
						message="Tem certeza que deseja excluir a disciplina?" header="Aviso"
						severity="alert" widgetVar="confirmation">

						<p:commandButton id="confirm" value="Sim"
							oncomplete="confirmation.hide()" action="#{mBDisciplina.remover}"
							ajax="false" />

						<p:commandButton id="decline" value="Não"
							onclick="confirmation.hide()" action="#{mBDisciplina.limpar}" />

					</p:confirmDialog>
					
				</p:column>
			</p:dataTable>
			<p:dialog widgetVar="disciplinaDialog">
				<ui:include src="../../comum/disciplina.xhtml">
					<ui:param name="disciplina" value="#{mBDisciplina.disciplinaVisualizacao}"/>
				</ui:include>
			</p:dialog>
		</h:form>
		
		<h:form>
			<p:panel header="Disciplina">
				<h:panelGrid columns="2">
					<h:outputText value="Nome*:" />
					<p:inputText value="#{mBDisciplina.disciplina.nome}" size="30" required="true" requiredMessage="Inisira o nome da disciplina"/>
					<h:outputText value="Sigla:" />
					<p:inputText value="#{mBDisciplina.disciplina.sigla}" size="20"/>
					<h:outputText value="Ementa:" />
					<p:inputTextarea value="#{mBDisciplina.disciplina.ementa}" style="width:400px" required="true" requiredMessage="Inisira a ementa da disciplina"/>
					<p:commandButton value="Cadastrar" rendered="#{!mBDisciplina.editavel}" action="#{mBDisciplina.cadastrar}" ajax="false"/>
					<p:commandButton value="Editar" rendered="#{mBDisciplina.editavel}" action="#{mBDisciplina.editar}" ajax="false"/>
					<p:commandButton value="Cancelar" onclick="form.reset()" action="#{mBDisciplina.limpar}" ajax="false"/>
				</h:panelGrid>
			</p:panel>
		</h:form>
	</ui:define>
</ui:composition>
</html>